package command.commandRunnable;

import dao.Factory;
import database.UserData;
import entity.Client;
import logger.LoggerManager;
import parsers.ClientXMLParser;
import parsers.UserDataParser;
import resurses.LoggerMessage;

import java.sql.SQLException;
import java.util.List;

/**
 * Created by alexander.makalov on 24.10.2014.
 */
public class CommandXmlParser implements Runnable {
    @Override
    public void run() {
        if(UserData.checkData()&& xmlFilePath != null){
            startParsing();
        }else {
            LoggerManager.getLogger().Log(LoggerMessage.UPDATE_USER_INFO, LoggerManager.LogLevel.INFO);
            UserDataParser userDataParser = new UserDataParser();
            userDataParser.startParsing();
            startParsing();
        }
    }

    private void startParsing(){
        ClientXMLParser clientXMLParser = new ClientXMLParser(xmlFilePath);
        clientXMLParser.startParsing();
        Factory.getInstance().getClientDAO().saveAllClients(clientXMLParser.getClientsList());
    }

    public String getXmlFilePath() {
        return xmlFilePath;
    }

    public void setXmlFilePath(String xmlFilePath) {
        this.xmlFilePath = xmlFilePath;
    }

    private String xmlFilePath;
}
